def n(a):    
    if a == 1: return False    
    test = True    
    b = a - 1    
    while b > 1:    
        if not a % b:    
            test = False                
            break    
        b -= 1        
    return test   
      
c = input()  
r = []  
for i in range(len(c)):  
    for b in range(i + 1,len(c) + 1):  
        a = int(c[i:b]) 
        if n(a):  
            r += [a]  
print(max(r) if r else 0)
